<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%String path = request.getContextPath();%>
<html>
	<head>
		<SCRIPT type="text/javascript" src="<%=path%>/js/json2.js"></SCRIPT>
		<SCRIPT type="text/javascript" src="<%=path%>/js/ajaxUtil.js"></SCRIPT>
		<SCRIPT type="text/javascript">
		var submitData = {}; //提交数据
		var resultData = {}; //返回数据	
		
		//发送ajax请求		
		function sendAjaxRequest(url) {
			var paramStr="";
			ajaxRequest(url, paramStr, ajaxCallBack);
		}
		
		//ajax回调函数
		function ajaxCallBack(oRequest) {
			document.write("ajax请求成功："+oRequest.responseText);
			//alert(oRequest.responseText);
			
			/**
			document.getElementsByName("jsonResult")[0].value = oRequest.responseText;
			resultData = JSON.parse(oRequest.responseText);
			var scriptCode = document.getElementsByName("scriptCode")[0].value;
			document.getElementsByName("result")[0].value = eval(scriptCode)? eval(scriptCode) : "";
			*/
			//var oJSON = eval('(' + oRequest.responseText + ')'); //返回JSON字符串转化为javascript对象的方法一
			//var json = JSON.parse(oRequest.responseText);  //返回JSON字符串转化为javascript对象的方法二
		}
		
		//提交数据脚本
		function submitStript01() {
			var str = 'submitData.id = "1";'
			return str;
		}
		
		//返回数据脚本
		function returnScript01() {
			var str = 'resultData.id\n';
			return str;
		}
		
		//提交数据脚本
		function submitStript02() {
			var str = 'submitData.userList = ["a","b","c","d"];\n';
			return str;
		}
		
		//返回数据脚本
		function returnScript02() {
			var str = 'resultData.userList[3]\n';
			return str;
		}
		//提交数据脚本
		function submitStript03() {
			var str = 'submitData.valueMap = {"newKey01":"newValue01","newKey02":"newValue02","newKey03":"newValue03"};\n';
			return str;
		}
		
		//返回数据脚本
		function returnScript03() {
			var str = 'resultData.valueMap.newKey03;\n';
			return str;
		}
		
		
		
		
		
		</SCRIPT>
	</head>
	
	<body>
	<input type="button" onclick="sendAjaxRequest('/ajax/test/hello.do')" value="show">
	
	<input type="button" onclick="sendAjaxRequest('/ajax/test/helloPrintOut.do')" value="showFromWri">
	
	</body>
</html>